package com.seeyon.apps.hems.initializer;

import com.seeyon.apps.hems.kit.DBKit;
import com.seeyon.ctp.common.AbstractSystemInitializer;
import com.seeyon.ctp.common.log.CtpLogFactory;
import org.apache.commons.logging.Log;

import java.util.List;
import java.util.Map;

public class SyncPluginInitializer extends AbstractSystemInitializer {
	private static final Log log = CtpLogFactory.getLog(SyncPluginInitializer.class);
	public void initialize() {
		try {

			StringBuilder stbSql = new StringBuilder();
			stbSql.append("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'BATCH_PABEL_PRINT_DATA'");
			List<Map<String, Object>> dataList = DBKit.excuteSQL(stbSql.toString(), null);
			if(dataList.isEmpty()){
				StringBuilder stb = new StringBuilder();
				stb.append("CREATE TABLE BATCH_PABEL_PRINT_DATA (").append("\r\n");
				stb.append("ID bigint NOT NULL PRIMARY KEY,").append("\r\n");
				stb.append("CREATE_MEMBER_ID bigint NULL,").append("\r\n");
				stb.append("CREATE_DATE datetime NULL,").append("\r\n");
				stb.append("BATCH_PABEL_PRINT_ID ntext NULL)").append("\r\n");
				log.info("创建数据库表sql语句:"+stb.toString());
				int num = DBKit.createTable(stb.toString());
				log.info("sql语句执行影响条数:"+num);
			}
		} catch (Exception e) {
			log.error("创建数据库表失败:", e);
		}
	}
	
	
}
